<template>
  <div class="container">
    <data-view
      ref='dataView'
      propViewKey="dept_demand"
      propViewForm="dept/demand/detail.vue"
      :propFlowKey="propFlowKey"
      @extra-button-click="extraButtonClick"
      :propPreQueryWrapper="$newWrapper().eq('ref_table', 'DEPT_APPLY')"
      :propIsTdesign="true"
    />
  </div>
</template>

<script>

export default {
  name: 'demand',
  data() {
    return {

    }
  },
  props: ['propFlowKey'],
  methods: {
    extraButtonClick(para) {
      let {key: buttonKey} = para.button
      if (buttonKey == 'merge_demand') { //客户端操作
        let demandAutos = para.data.filter(o => o.flowStatus == 'submit')
        if (demandAutos instanceof Array) {
          if (demandAutos.length == 0) {
            this.utilMessage.error('请先选择需求单,待审核状态可以汇总')
            return false
          }
        }
        this.mergeDemand(demandAutos)
      }
    },

    mergeDemand(demandAutos) {
      let that = this
      this.$ajax.post('/dept/demand/toDemandSum', demandAutos).then(resp => {
        that.$refs.dataView.fetchData()
        that.$confirm('响应成功，是否继续操作？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        }).then(() => {
          global.utils.openForm({
            routeName: 'dept/demandsum/index',
            url: 'dept/demandsum/index.vue',
            para: {id: resp.data.id, propFlowKey: 'wm_dist'},
            title: '需求汇总'
          })
          that.$refs.dataView.fetchData()
          // global.utils.openMenu('dept/demandsum/index', {id: resp.data.id})
        }).catch(() => {})
      })
    }
  },
  computed: {

  },

  components: {

  }
}
</script>

<style lang="scss" scoped>
  .container {
    height: 100%;
    background-color: #fff;
  }
</style>
